package site.lanmushan.framework.query.util;

import site.lanmushan.framework.dto.QueryInfo;
import site.lanmushan.framework.mapper.params.WhereQueryParam;
import site.lanmushan.framework.mapper.wrapper.QueryParamWrapper;
import site.lanmushan.framework.mapper.wrapper.QueryWrapper;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author Administrator
 */
public class QueryInfoUtil {
    /**
     * 转换为查询条件
     *
     * @param queryInfo
     * @return
     */
    public static QueryWrapper toQueryWrapper(QueryInfo queryInfo) {
        List<WhereQueryParam> list = queryInfo.getParList().stream().map(it -> {
            Object value = it.getValue();
            return new WhereQueryParam(it.getKey(), it.getOperate(), value, it.getIndex());
        }).collect(Collectors.toList());
        QueryParamWrapper queryWrapper = new QueryParamWrapper();
        return queryWrapper.setQueryParam(list);
    }
}
